Skip to content

Add commodity constraints input and validation - #1487

Merged
tsmbland merged 15 commits into
mainfrom
add-commodity-constraints-input-and-validation
Aug 27, 2026
Merged

Add commodity constraints input and validation#1487
tsmbland merged 15 commits into
mainfrom
add-commodity-constraints-input-and-validation

Conversation

@dc2917

@dc2917 dc2917 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds a new module for reading and validating an input csv file for commodity constraints.

Commodity constraints are stored in a new CommodityConstraint struct, and the set of constraints provided are read and stored in a CommodityConstraintsMap type, which maps CommodityConstraints by region ID and year.

CommodityConstraints have a single field, limits, which stores the range of values to which the commodity is constrained.

An example commodity_constraints.csv file has been added to the "simple" setup for demonstration, and a corresponding schema has been added.

Fixes #1448

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@dc2917

dc2917 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@tsmbland I've taken a stab at this but some feedback would be helpful before I add tests

@tsmbland tsmbland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start, but a few comments

Comment thread src/input/commodity/constraints.rs Outdated
Comment thread src/input/commodity/constraints.rs Outdated
Comment thread src/input/commodity/constraints.rs Outdated
Comment thread src/commodity.rs Outdated
Comment thread src/commodity.rs Outdated
Comment thread src/input/commodity/constraints.rs
dc2917 added 3 commits August 25, 2026 17:23
- Cleaner parsing of region_id
- Change units of limits from money to flow
- Store time slice selection and balance type in `CommodityConstraint` struct
- Store vectors of `CommodityConstraint`s in `CommodityConstraintMap`
@dc2917
dc2917 force-pushed the add-commodity-constraints-input-and-validation branch from c872f0a to 273b323 Compare August 25, 2026 16:23
@dc2917
dc2917 force-pushed the add-commodity-constraints-input-and-validation branch from 273b323 to 328243d Compare August 25, 2026 16:28
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.35%. Comparing base (236974e) to head (3363674).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/input/commodity/constraints.rs 92.52% 2 Missing and 11 partials ⚠️
src/input/commodity.rs 66.66% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1487      +/-   ##
==========================================
+ Coverage   90.31%   90.35%   +0.03%     
==========================================
  Files          60       61       +1     
  Lines        8663     8850     +187     
  Branches     8663     8850     +187     
==========================================
+ Hits         7824     7996     +172     
- Misses        525      529       +4     
- Partials      314      325      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dc2917
dc2917 force-pushed the add-commodity-constraints-input-and-validation branch from be131f2 to 03f77ef Compare August 26, 2026 07:50
@dc2917
dc2917 marked this pull request as ready for review August 26, 2026 07:51
@dc2917
dc2917 requested a review from tsmbland August 26, 2026 07:51

@tsmbland tsmbland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good on the whole, just a few suggestions

Comment thread examples/simple/commodity_constraints.csv Outdated
Comment thread schemas/input/commodity_constraints.yaml Outdated
Comment thread schemas/input/commodity_constraints.yaml
Comment thread schemas/input/commodity_constraints.yaml Outdated
Comment thread src/input/commodity/constraints.rs Outdated
Comment thread src/input/commodity/constraints.rs Outdated
Comment thread src/input/commodity.rs Outdated
Comment thread src/input/commodity/constraints.rs Outdated
Comment thread src/input/commodity/constraints.rs
Comment thread src/input/commodity/constraints.rs
@dc2917
dc2917 requested a review from tsmbland August 26, 2026 14:06

@tsmbland tsmbland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Still a small error in the tests. As I don't think it affects the validity of the tests I'll approve, but probably worth fixing up for the sake of correctness!

@tsmbland
tsmbland merged commit 547dc47 into main Aug 27, 2026
8 checks passed
@tsmbland
tsmbland deleted the add-commodity-constraints-input-and-validation branch August 27, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add file reading and validation code for commodity constraints

2 participants